#include<iostream>
using namespace std;
#include<vector>
#include<climits>
int gcd(int a, int b) {
	int a1, a2;
	if (a > b)
		a1 = a, a2 = b;
	else
		a1 = b, a2 = a;
	while (a2 > 0) {
		int now = a1 % a2;
		a1 = a2;
		a2 = now;
	}
	return a1;
}
int main() {
	int n, cnt = 0;
	cin >> n;
	vector<int> arr(n);
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
		if (arr[i] == 1) {
			++cnt;
		}
	}
	if (cnt) {
		cout << n - cnt;
		return 0;
	}
	int ans = INT_MAX;
	for (int i = 0; i < n - 1; ++i) {
		int x = arr[i];
		int sum = 0;
		for (int j = i + 1; j < n; ++j) {
			++sum;
			x = gcd(x, arr[j]);
			if (x == 1) {
				ans = min(ans, sum + n - 1);
				break;
			}
		}
	}
	if (ans == INT_MAX)
		ans = -1;
	cout << ans;
	return 0;
}